package com.yly.doctorapp.widget;

import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.PopupWindow;

import com.yly.doctorapp.R;
import com.yly.doctorapp.base.DoctorAppApplication;
import com.yly.doctorapp.constant.Configution;
import com.zhcx.zhcxlibrary.utils.ToastUtils;

import org.xutils.common.Callback;
import org.xutils.common.util.LogUtil;
import org.xutils.http.RequestParams;
import org.xutils.x;

public class ShowPop {
    private Context mContext;
    private EditText edit_yao;

    public ShowPop(Context mContext, EditText edit_yao) {
        this.mContext = mContext;
        this.edit_yao = edit_yao;
    }
    public void showProductionPop(){
        if (null == DoctorAppApplication.mPopup){
            View view = LayoutInflater.from(mContext).inflate(R.layout.layout_pop, null);
            ListView lv_production = view.findViewById(R.id.lv_production);
            lv_production.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                }
            });
            DoctorAppApplication.mPopup = new PopupWindow(view, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
            DoctorAppApplication.mPopup.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
            DoctorAppApplication.mPopup.setBackgroundDrawable(new BitmapDrawable());
            DoctorAppApplication.mPopup.showAsDropDown(edit_yao, 0, 0);
//            DoctorAppApplication.mPopup.setAnimationStyle(R.style.myTransparent);
            DoctorAppApplication.mPopup.setFocusable(true);
            DoctorAppApplication.mPopup.update();
        }else {

        }
    }

    //拿到产品列表
    public void initGetData(String keyword){
        RequestParams params = new RequestParams(Configution.HOST + Configution.QUERYPRODUCTIONITEM);
        params.addBodyParameter("doctorId", DoctorAppApplication.mUserBean.getDoctorid() + "");
        params.addBodyParameter("keywords", keyword);
        x.http().get(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                LogUtil.d(result);
                showProductionPop();
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                ToastUtils.show(mContext, "网络连接失败", 100);
            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });
    }
}
